package com.yxw.rabbitMQDemo;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;

/**
 * Created by hp on 2015/12/9.
 */
public class Sender {
    private static String QUEUE_NAME = "YXW_TEST_QUEUE";
    public static final boolean durable=true;

    public static void main(String[] args) throws IOException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, durable, false, false, null);
        for(int i=0;i<10000;i++){
            String message = "Hello World!"+i;

            channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'"+i);
        }

        channel.close();
        connection.close();
    }
}
